package cn.it.shop.action;

import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.it.shop.model.Product;

@SuppressWarnings("serial")
@Controller
@Scope("prototype")
public class ProductAction extends BaseAction<Product> {
	public String queryJoinCategory() {
		pageMap = new HashMap<String, Object>();
		List<Product> productList = productService.queryJoinCategory(
				model.getName(), page, rows);
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + productList);
		pageMap.put("rows", productList);
		pageMap.put("total", productService.getCount(model.getName()));
		return "jsonMap";
	}

	public void save() {

		String pic = fileUpload.uploadFile(fileImage);
		model.setPic(pic);
		// 商品入库
		productService.save(model);

	}

	public void update() {
		String pic = fileUpload.uploadFile(fileImage);
		System.out.println(pic);
		model.setPic(pic);
		System.out.println(model);
		// 商品入库
		productService.update(model);
	}

	public String deleteByIds() {
		productService.deleteByIds(ids);
		inputStream = new ByteArrayInputStream("true".getBytes());
		return "stream";
	}
}
